package main.handleException;

import main.util.ResultData;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 异常处理类
 * @author wfy
 *
 */
@ControllerAdvice
public class ExceptionHandle {

	private final static Logger LOG = LoggerFactory.getLogger(ExceptionHandle.class);
	
	@ExceptionHandler(value=Exception.class)
	@ResponseBody
	public ResultData handleException(Exception e) {
		
		if(e instanceof BizException) {
			BizException boyException = (BizException) e;
			return ResultData.generateFailResultData(boyException.getCode(), boyException.getMessage());
		}
		
		LOG.error("x系统异常{}",e);
		
		return ResultData.generateFailResultData(-1,"未知错误!");
	}
	
}
